package com.food.platformmsgmanagement.domain;

import com.food.platformmsgmanagement.adapter.inbound.AlimentDTO;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.PersistenceConstructor;
import org.springframework.data.relational.core.mapping.Column;
import org.springframework.data.relational.core.mapping.Table;

import java.util.List;

/**
 * 美食信息 实体类 聚合
 * @author 24270
 */
@Table("aliment")
public class Aliment {
    @Id
    @Column(value = "id")
    private AlimentId id;
    private String title;
    @Column(value = "mainText")
    private String mainText;
    @Column(value = "imgList")
    private List<String> imgList;
    private Status status;

    @PersistenceConstructor
    public Aliment(String title, String mainText, List<String> imgList) {
        this.id = new AlimentId();
        this.title = title;
        this.mainText = mainText;
        this.imgList = imgList;
        this.status = Status.POLISHED;
    }

    public Aliment(String id, String title, String mainText, List<String> imgList) {
        if(id != null) {
            this.id = new AlimentId();
            this.id.setId(id);
        }else {
            this.id = new AlimentId();
        }
        this.title = title;
        this.mainText = mainText;
        this.imgList = imgList;
        this.status = Status.POLISHED;
    }

    public void publish() {
        status = status.changeTo(Status.POLISHED);
    }

    public void invisible() {
        status = status.changeTo(Status.INVISIBLE);
    }

    public void remove() {
        status = status.changeTo(Status.REMOVED);
    }

    public Status status() {
        return this.status;
    }

    public String id() {
        return this.id.value();
    }

    public String title() {
        return this.title;
    }

    public String mainText() {
        return this.mainText;
    }

    public List<String> imgList() {
        return this.imgList;
    }

    /**
     * 放进去url或者数据表中的id之类的
     * @param img
     */
    public void addImg(String img) {
        imgList.add(img);
    }

    public AlimentDTO makeAlimentDTO() {
        AlimentDTO dto = new AlimentDTO();
        dto.setId(this.id());
        dto.setTitle(this.title);
        dto.setMainText(this.mainText);
        dto.setImgList(this.imgList);
        return dto;
    }
}
